package com.bytedance.article.common.nativecrash;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import java.io.File;

public class NativeCrashInit {
    private static boolean a;

    static {
        try {
            System.loadLibrary("ttnativecrash");
        } catch (UnsatisfiedLinkError v0) {
            Log.e("womendejia", Log.getStackTraceString(((Throwable) v0)));
        }
    }

    private static native boolean Register(String arg0, String arg1);

    private static native void Unregister();

    private static String a(Context arg3) throws NullPointerException {
        String v0 = null;
        if (arg3 == null) {
            throw new NullPointerException("Context is NUll");
        }

        try {
            if (arg3.getCacheDir() != null) {
                return arg3.getCacheDir().getPath();
            }

            File v1_1 = arg3.getDir("/data/data/" + arg3.getPackageName() + "/cache/", 0);
            if (v1_1 == null) {
                return v0;
            }

            v0 = v1_1.getPath();
        } catch (Throwable v1) {
        }

        return v0;
    }

    public static void a(Context arg4, String arg5, String arg6, String arg7) {
        if (!NativeCrashInit.a && arg4 != null && !TextUtils.isEmpty(((CharSequence) arg5)) && !TextUtils.isEmpty(((CharSequence) arg6)) && !TextUtils.isEmpty(((CharSequence) arg7))) {
            try {
                File v0_1 = new File(NativeCrashInit.a(arg4), arg5);
                if (!v0_1.exists()) {
                    v0_1.mkdirs();
                }

                File v2 = new File(v0_1, arg6 + System.currentTimeMillis() + ".log");
                if (TextUtils.isEmpty(v2.getAbsolutePath())) {
                    return;
                }

                if (!NativeCrashInit.Register(v2.getAbsolutePath(), arg7)) {
                    return;
                }

                NativeCrashInit.a = true;
            } catch (Throwable v0) {
                v0.printStackTrace();
            }
        }
    }

    private static native void makecrash();
}

